﻿<section id="app" class="container-fluid case" style="background-color: white;">
    <ul class="nav nav-tabs m15_t" id="myTab">
        <li class="active"><a href="#home" data-toggle="tab">基本信息</a></li>
        <li><a href="#permissions" data-toggle="tab">物料明细</a></li>
    </ul>
    <form class="form-horizontal m15_t" id="form">
        <div class="tab-content">
            <div class="tab-pane fade in active" id="home">
                <div class="form-group">
                    <label class="wd100 control-label"><span class="WdateFmtErr">*</span>单据编号：</label>
                    <div class="wd400 m15_l">
                        <input class="form-control input-xs" name="orderId" type="text" value="@(ViewBag.NextId)" data-options="required:true,prompt:'单据编号'">
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">是否空容器：</label>
                    <div class="wd400 m15_l">
                        <input type="checkbox" name="isContainer" autocomplete="off">
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label m15_l">入库库位：</label>
                    <div class="input-group wd400 m15_l">
                        <input type="hidden" class="form-control" name="warehouseUnitId" value="" />
                        <input type="text" class="form-control" name="warehouseUnitCode" maxlength="20" placeholder="入库库位" autocomplete="off" disabled />
                        <span class="input-group-addon" style="margin-left:20px;">
                            <i data-modal="/Module/WarehouseUnit" data-title="入库库位" data-width="800" data-height="570" class="glyphicon glyphicon glyphicon-align-justify"></i>
                        </span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">站台：</label>
                    <div class="wd400 m15_l">
                        <input class="form-control" type="text" name="stationNo" autocomplete="off" data-options="prompt:'站台'">
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">备注：</label>
                    <div class="wd400 m15_l">
                        <input class="form-control" type="text" name="remark" maxlength="50" autocomplete="off" data-options="prompt:'备注'">
                    </div>
                </div>
            </div>
            <!--菜单-->
            <div class="tab-pane fade" id="permissions">
                <a class="btn btn-default btn-sm" data-modal="/Module/ProductItem" data-title="新增物料" data-width="600" data-height="197"><span class="glyphicon glyphicon-plus"></span> 新增</a>
                <a class="btn btn-default btn-sm" data-modal="/Module/ProductBarCode" data-title="扫码物料" data-width="600" data-height="120"><span class="glyphicon glyphicon-plus"></span> 扫码</a>
                <div class="panel panel-default">
                    <table class="table table-bordered table-hover privileges">
                        <thead>
                            <tr>
                                <th class="t_l">材料名称</th>
                                <th class="t_c wd75">数量</th>
                                <th class="t_c wd120">批号1</th>
                                <th class="t_c wd120">批号2</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr class="noRecord" v-if="inventoryItems.length==0">
                                <td colspan="4" class="t_c">暂无记录</td>
                            </tr>
                            <tr v-for="item in inventoryItems">
                                <td class="t_l">{{item.ProductName}}</td>
                                <td class="t_c">{{item.Quantity}}</td>
                                <td class="t_c">{{item.LotNo1}}</td>
                                <td class="t_c">{{item.LotNo2}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </form>
</section>
<script type="text/javascript">
    function Tip_success(word) {
        Topro.UI.Tip_success(word);
    }

    var app = new Vue({
        el: '#app',
        data: {
            inventoryItems: []
        },
        mounted() {
            window.addInventoryItem = this.addStockInItem;
            window.saveInventoryItem = this.saveInventoryItem;
        },
        methods: {
            addStockInItem(obj) {
                this.inventoryItems.push(obj)
            },
            saveInventoryItem() {
                debugger;
                //入库
                var stockIn = {};
                //订单号
                stockIn.orderId = $("input[name='orderId']").val();
                //坐标
                stockIn.coordinate = $("input[name='coordinate']").val();
                //容器类型
                //stockIn.containerType = $("select[name='containerType']").find("option:selected").val();
                //是否空容器
                stockIn.isContainer = $("input[name='isContainer']").is(':checked') == true ? 10 : 20;
                //库位
                stockIn.warehouseUnitId = $("input[name='warehouseUnitId']").val();
                //站台
                stockIn.stationNo = $("input[name='stationNo']").val();
                //备注
                stockIn.remark = $("input[name='remark']").val();

                Topro.UI.Ajax({
                    type: "POST",
                    url: "/StockIn/Save",
                    data: {
                        stockIn: stockIn,
                        inventoryItem: this.inventoryItems,
                    },
                    success: function (res) {
                        if (res.success) {
                            Topro.UI.Tip_success(res.message);
                            Topro.UI.DialogOpener().In.search();
                            Topro.UI.CloseDialog();
                            return false;

                        } else {
                            Topro.UI.Tip_danger("操作失败！" + res.message);
                            return false;
                        }
                    },
                    error: function (json) {
                        //disabled
                        $("button[name='save']").attr("disabled", false);
                        Topro.UI.Tip_warning("操作失败！请查看网络，请重试。");
                        return false;
                    }
                });
            }
        }
    })

    function addInventoryItem(obj) {
        window.addInventoryItem(obj);
    }

    function save() {
        window.saveInventoryItem();
    }

    function set(obj) {
        $("input[name='warehouseUnitId']").val(obj.warehouseUnitId);
        $("input[name='warehouseUnitCode']").val(obj.warehouseUnitCode);
    }
</script>